Learning Objectives

After completing this lesson, you'll be able to:

Instructions

In this lesson, you will:

Resources

Introduction

At a basic level, the SchemaScanner is fairly simple to operate. However, more complex scenarios involve how the different parameters are used and the exact values of the incoming data.

The Missing/Null/Empty Attributes parameter controls the schema when incoming data is without values:

Missing/Null/Empty Attributes parameter

However, this only applies to data where the entire dataset is without a particular attribute value. In this dataset, for example, every value for MarketType is null. MergedAddress also has null values, but not for every record:

Attributes without some values or all values

Given the above parameters, the output schema will not contain the MarketType field because it has no values:

Attribute without any values removed from schema feature

However, MergedAddress is included because some records still have values.

Now, say, for example, that we wanted to include MarketType in the output even though there are no values. There are two alternatives to the Ignore option:

Other options for Missing/Null/Empty Attributes

Because there are no data values, the SchemaScanner cannot scan the data to guess the data type. Instead, it can either use a default data type (a varchar of unknown length) or trace back through the workspace to find any clues to the data type.

In this case, the reader feature type has that information:

Reader feature type attributes

…so the SchemaScanner will use that and create an output schema where MarketType = varchar(21).

Exercise

Jennifer

Jennifer's market workspace now writes whatever schema it produces rather than the one it read, but it still covers a single market. She wants to bring the Vancouver farmers market data in alongside it, and give each day of the week its own output file with a schema that fits that day's data.

In this exercise, you will:

1) Open the Workspace

You can carry on from the previous exercise or start fresh. Either way, the second dataset can be brought in two ways, and it is worth knowing both: adding a reader is the obvious route, while pointing the existing dynamic reader at more files takes advantage of the fact that it does not care about schema.

Method #1: A New Reader

Method #2: Extend the Existing Reader

Adding a new CSV

2) Run the Workspace

The two datasets do not share a schema, which is the point. Seeing how the SchemaScanner reconciles them explains what it does when features disagree about which attributes exist.

Market Type is null or Offerings is null

3) Split the Output by Day

One file per market day is more useful than one combined file. Setting the file name from an attribute is what splits the output, and it also sets up the schema problem the next step solves.

Setting CSV File Name to Day

Missing values - Saturday Offerings

Entirely null value for Offerings on Wednesdays

4) Group the SchemaScanner by Day

Grouping makes the SchemaScanner emit one schema feature per group instead of one for everything. That is what lets each day's file describe only the attributes that day actually has.

SchemaScanner with a Group By on Day

Four schema features

Wednesday CSV doesn't have Offerings attribute because it has no values

5) Include Empty Attributes

Ignoring empty attributes is not always what you want. Interpreting the upstream schema keeps them, and FME works out the data type from wherever it can find it earlier in the workspace.

MarketType included with a derived type

You have combined two datasets with different schemas through one dynamic reader, split the output by day, and given each day its own schema. Switching between ignoring and interpreting empty attributes controls whether a column survives into an output that has no values for it.

 

Tips